package cn.edu.fzu.homemaking.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import cn.edu.fzu.homemaking.domain.enums.LabelStatusEnum;
import cn.edu.fzu.homemaking.service.SysLabelService;
import cn.edu.fzu.homemaking.web.Result;
import cn.edu.fzu.homemaking.web.RetCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author yifan
 * @date 2023/4/4
 */
@Api(tags = "sys-标签管理")
@RestController
@RequestMapping("/api/sys")
public class SysLabelController {

    @Resource
    private SysLabelService sysLabelService;

    @ApiOperation(value = "获取标签列表")
    @ApiImplicitParams({ @ApiImplicitParam(name = "name", required = false, value = "标签名称"),
            @ApiImplicitParam(name = "status", readOnly = false, value = "状态"),
            @ApiImplicitParam(name = "pageNum", required = false, value = "页码（不填返回全部数据）"),
            @ApiImplicitParam(name = "pageSize", required = false, value = "页面大小（不填返回全部数据）")})
    @GetMapping("label/list")
    public Result listLabels(String name, LabelStatusEnum status, Integer pageNum, Integer pageSize) {
        Result result = sysLabelService.listLabels(name, status, pageNum, pageSize);
        return result;
    }


    @ApiOperation(value = "批量添加标签")
    @PostMapping("auth/label/add")
    public Result addLabels(@RequestBody List<String> labelNames) {
        sysLabelService.addLabels(labelNames);
        return new Result(RetCode.SUCCESS, "添加成功！");
    }


    @ApiOperation(value = "修改标签")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", required = true, value = "标签id"),
            @ApiImplicitParam(name = "name", readOnly = false, value = "名称"),
            @ApiImplicitParam(name = "status", readOnly = false, value = "状态") })
    @PostMapping("auth/label/update")
    public Result updateLabel(Long id, String name, LabelStatusEnum status) {
        sysLabelService.updateLabel(id, name, status);
        return Result.SUCCESS;
    }


    @ApiOperation(value = "获取公司的标签")
    @ApiImplicitParams({ @ApiImplicitParam(name = "companyId", required = true, value = "公司id"),
            @ApiImplicitParam(name = "pageNum", required = false, value = "页码（不填返回全部数据）"),
            @ApiImplicitParam(name = "pageSize", required = false, value = "页面大小（不填返回全部数据）") })
    @GetMapping("auth/label/getByCompany")
    public Result getByCompanyId(Long companyId, Integer pageNum, Integer pageSize) {
        Result result = sysLabelService.getByCompanyId(companyId, pageNum, pageSize);
        return result;
    }
}
